package com.yrj.test1;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;

    String[] boyfaces = {"风流倜傥","气宇轩昂","相貌平平","面目狰狞"};
    String[] girlfaces = {"沉鱼落雁","闭月羞花","亭亭玉立","相貌平平"};

    String[] attacks_desc={
            "%s使出了一招【背心钉】，转到对方身后，一掌向%s背心的灵台穴拍去",
            "%s大喝一声，身形下伏，一招【霹雷坠地】，锤向%s双腿",
            "%s运气于掌，一瞬间掌心变得血红，一式【掌心雷】，推向%s"
    };
    String[] injureds_desc={
            "结果%s退了半步，毫发无损",
            "%s吐了一口血",
            "%s摇摇晃晃，倒在了地上"
    };
    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);

    }


    public char getGender() {
        return gender;
    }
    public void setGender(char gender) {
        this.gender = gender;
    }
    public String getFace() {
        return face;
    }
    public void setFace(char gender) {
        Random r = new Random();
        //长相随机
        if(gender == '男'){
            int index = r.nextInt(boyfaces.length);
            this.face = boyfaces[index];
        }
        else if(gender == '女'){
            int index = r.nextInt(girlfaces.length);
            this.face = girlfaces[index];
        }
        else{
            this.face = "面目狰狞";
        }
    }
    public Role() {

    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }
    //定义一个方法用来攻击敌人
    //方法的调用者去攻击参数
    public void attack(Role role) {
        Random r = new Random();
        int index = r.nextInt(attacks_desc.length);
        String KungFu = attacks_desc[index];
        System.out.printf(KungFu,this.getName(),role.getName());
        System.out.println();
        //计算造成的伤害
        int hurt = r.nextInt(20) + 1;

        //剩余血量
        int remainBlood = role.getBlood() - hurt;
        //对剩余血量验证
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        //修改被打的人的血量
        role.setBlood(remainBlood);
        //this表示方法的调用者
        if(remainBlood > 80){
            System.out.printf(injureds_desc[0],role.getName(),role.getGender());
        }else if(remainBlood > 40&&remainBlood < 80){
            System.out.printf(injureds_desc[1],role.getName(),role.getGender());
        }else if(remainBlood > 0&&remainBlood < 40){
            System.out.printf(injureds_desc[2],role.getName(),role.getGender());
        }
        System.out.println();
    }
    public void showRoleInfo(){
        System.out.println("姓名为："+getName());
        System.out.println("血量为："+getBlood());
        System.out.println("性别为："+getGender());
        System.out.println("长相为："+getFace());
    }
}